package com.xneure.code.log;

import java.io.IOException;
import java.io.OutputStream;
import com.xneure.code.log.ILog.Level;

public class SysPrintHandle extends OutputStream{
	private ILog log;
	private OutputStream out;
	private Level l;

	public SysPrintHandle(ILog log,Level l,OutputStream out){
		log.setSysHandle(true);
		this.log = log;
		this.l = l;
		this.out = out;
	}

	@Override
	public void write(int c) throws IOException{
		out.write(c);
		log.print(l,String.valueOf(c));
	}

	public void write(String str) throws IOException{
		write(str.getBytes());
		log.print(l,str);
	}
	@Override
	public void write(byte[] b) throws IOException{
		out.write(b);
		log.print(l,new String(b));
	}

	@Override
	public void write(byte[] b,int off,int len) throws IOException{
		out.write(b,off,len);
		log.print(l,new String(b,off,len));
	}

	@Override
	public void flush() throws IOException{
		out.flush();
	}
	
}
